<?php

namespace app\admin\controller;
use app\base\controller\Base;
use think\Request;
use think\Cache;
use think\Config;
use think\Session;


class Configs extends Base
{
    public  $model;

    public function __construct()
    {
   $this->model = model("Configs");
        parent::__construct();
    }

    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {//
        $base = [42,45,54,55,60,61];
        $sms_config = array_column(get_m_config("sms_config"),"id");
        $market_day = array_column(get_m_config("market_day"),"id");
        $thirdparty= array_column(get_m_config("thirdparty"),"id");

        $arr = array_merge($base,$sms_config,$market_day,$thirdparty);
        $where['id'] = ["in",$arr];
        $res = $this->model->where($where)->select();
        if($res){
            return sucessJson("查询成功",$res);
        }
        return failJson("失败");
        //时间的处理

    }


    /**
     * @return \think\response\Json 配置更新
     */
    public function updateit(){
        $base = [42,45,54,55,60,61];
        $sms_config = array_column(get_m_config("sms_config"),"id");
        $market_day = array_column(get_m_config("market_day"),"id");
        $thirdparty= array_column(get_m_config("thirdparty"),"id");
        $arr = array_merge($base,$sms_config,$market_day,$thirdparty);
       // $arr = [38,46,39,40,41,51,52,53,42,45];

        if(!in_array($this->id,$arr)){
            return     failJson("id异常");
        }

        $arrpay =$thirdparty;//支付方式 thirdparty
        $jypay = $market_day;//交易日 market_day
        $dxpay = $sms_config;//短信交易 sms_config


        if(in_array($this->id,$arrpay)){ //支付方式的处理
            $this->model->where("id","in",$arrpay)->update(['is_position'=>0]);
        }

        if(in_array($this->id,$jypay)){ //交易日的处理
            $this->model->where("id","in",$jypay)->update(['is_position'=>0]);
        }

        if(in_array($this->id,$dxpay)){ //交易日的处理
            $this->model->where("id","in",$dxpay)->update(['is_position'=>0]);
        }
        $neArr = array_merge($arrpay,$jypay,$dxpay );

      if(!in_array($this->id,$neArr)){
            $data['value'] = $this->value;
        }

        if(isset($this->is_position)){
            $data['is_position'] = 1;
        }




        // $data['type'] = 1;
        $res = $this->model->save($data,['id'=>$this->id]);
        //file_put_contents("ddddddddx.log",$this->model->getLastSql());
        if($res){
            return  sucessJson("设置成功");
        }else{
            return     failJson("设置失败");
        }
    }







}
